/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.TextField
 *  javafx.scene.layout.AnchorPane
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.salesReceipts;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.gys.common.business.SalesReceiptsUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.util.PrintService;
import com.gys.controller.BaseController;
import com.gys.controller.dataManger.ControllerManger;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.HashMap;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class RePrintBillController
extends BaseController
implements Initializable {
    private static final Logger log = LoggerFactory.getLogger(RePrintBillController.class);
    @FXML
    private TextField caseId;
    @FXML
    private AnchorPane pane;
    @Autowired
    private PrintService printService;

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.pane)) {
            return;
        }
        this.caseId.clear();
    }

    @FXML
    private void sureAction() {
        if (ObjectUtil.isEmpty(this.caseId.getText())) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u9500\u552e\u5355\u53f7\u4e0d\u80fd\u4e3a\u7a7a");
            alert.showAndWait();
            return;
        }
        if (!this.caseId.getText().startsWith("SD") || this.caseId.getText().length() != 20) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u9500\u552e\u5355\u53f7\u683c\u5f0f\u9519\u8bef");
            alert.showAndWait();
            return;
        }
        HashMap<String, Object> checkParam = new HashMap<String, Object>();
        checkParam.put("billNo", this.caseId.getText());
        HttpJson checkHttpJson = SalesReceiptsUtil.checkPrintBill(checkParam);
        if (checkHttpJson.isSuccess()) {
            Integer result = (Integer)JSON.parseObject((String)checkHttpJson.getMsg(), Integer.class);
            String message = "";
            if (result == 0) {
                message = "\u8be5\u9500\u552e\u5355\u53f7\u4e0d\u5b58\u5728";
            } else if (result == 1) {
                message = "\u8be5\u9500\u552e\u5355\u4e3a\u6302\u8d77\u72b6\u6001\uff0c\u65e0\u6cd5\u6253\u5370";
            } else if (result == 2) {
                message = "\u8be5\u9500\u552e\u5355\u5df2\u5e9f\u5f03\uff0c\u65e0\u6cd5\u6253\u5370";
            } else if (result == 3) {
                message = "\u8be5\u9500\u552e\u5355\u53f7\u6682\u4e0d\u5141\u8bb8\u6253\u5370";
            }
            if (ObjectUtil.isNotEmpty(message)) {
                Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", message);
                alert.showAndWait();
                return;
            }
        } else {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", checkHttpJson.getMsg());
            alert.showAndWait();
            return;
        }
        boolean result = this.printService.printSale(this.caseId.getText());
        if (result) {
            this.cancelAction();
        }
    }

    @FXML
    private void cancelAction() {
        this.pane.getScene().getWindow().hide();
    }
}

